<?php
include 'admin_passport_action_lib.php';

if ($s_Action == 'insert' || $s_Action == 'update') {
    
    // <editor-fold defaultstate="collapsed" desc="Insert & Update">
    if ($f_actionid == '') { raise_error('No ID.'); }

    $a_row = array(
        'actionname'   => $f_actionname  ,
        'actiontype'   => $f_actiontype  ,
        'actionstatus' => $f_actionstatus,
        'note'         => $f_note        ,
        'updaterid'    => $s_UserID   ,
        'updatedate'   => $f_updatedate  ,
    );
    
    $db_query  = db_get_query($a_tablecolumns_namhoa_passport_action);
    $db_query  = $db_query . " where actionid = '$f_actionid'";
    $db_result = db_query($db_conn, $db_query);
    
    if ($s_Action == 'insert') {
        
        $d_total = db_num_rows($db_result);
        
        if ($d_total) { raise_error( 'Action ID is NOT Available.'); }
        
        $a_row['actionid'   ] = $f_actionid;
        $a_row['creatorid'  ] = $s_UserID;
        $a_row['insertdate' ] = $f_insertdate;

        db_insert_row($db_conn, $a_row, 'passport_action');
    } 
    else {
        if(!($d_passport_action = db_fetch($db_result))){ raise_error('Select None.'); }
    
        db_update_row($db_conn, $a_row, 'passport_action', "actionid = '$f_actionid'");
    }
    // </editor-fold>
} 
else if ($s_Action == 'delete') {    
    
    // <editor-fold defaultstate="collapsed" desc="Delete">
    $f_actionids = array($f_actionid);

    if (isset($_REQUEST['actionids'] )) { $f_actionids = $_REQUEST['actionids'] ; }

    $s_Where = "actionid in ('" . implode("','", $f_actionids) . "')";

    db_delete_row($db_conn, 'passport_action', $s_Where);
    // </editor-fold>
}
else {
    raise_error('No Action.');
}

// <editor-fold defaultstate="collapsed" desc="Set Cache">
access_cachefile($s_Cache_Path, 'passport_actions', array('db_conn' => $db_conn, 'generate' => true));
// </editor-fold>

local_redirect('admin_passport_action_list.php?' . $s_QueryString_Page);
?>